#include<bits/stdc++.h>
using namespace std;

int d[100005] {}, v[100005] {}, a[100005]{};
int p[100005] {};
bool f[1000005] {};

int main() {
    ios::sync_with_stdio(0);
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    for (int z = 1; z <= t; z++) {
        memset(d, 0, sizeof(d));
        memset(v, 0, sizeof(v));
        memset(a, 0, sizeof(a));
        bool fa = 1, fb = 1, fc = 1;
        int n, m, l, vv;
        cin >> n >> m >> l >> vv;
        for (int i = 1; i <= n; i++) {
            cin >> d[i] >> v[i] >> a[i];
            if (a[i] != 0) {
                fa = 0;
            }
            if (a[i] <= 0) {
                fb = 0;
            }
            if (a[i] >= 0) {
                fc = 0;
            }
        }
        for (int i = 1; i <= m; i++) {
            cin >> p[i];
            f[p[i]] = 1;
        }
        sort(p + 1, p + m + 1);
        if (fa) {
            int ans = 0;
            for (int i = 1; i <= n; i++) {
                if (d[i] <= p[m] && v[i] > vv) {
                    ans++;
                }
            }
            cout << ans << " " << (ans == 0 ? m : m - 1) << "\n";
        } else if (fb) {
            int ans = 0;
            for (int i = 1; i <= n; i++) {
                if (1.0 * (vv * vv - v[i] * v[i]) / (2 * a[i]) < p[m] - d[i]) {
                    ans++;
                }
            }
            cout << ans << " " << (ans == 0 ? m : m - 1) << "\n";
        } else if (fc) {
            int ans = 0, ans1 = m;
            cout << ans << " " << ans1 << "\n";
        } else {
            int ans = 0, ans1 = m;
            cout << ans << " " << ans1 << "\n";
        }
    }

    return 0;
}
